// 待收货
var tblWaitReceive;
// 收货中
var tblReceiving;
// 已完成
var tblComplete;
// 已取消
var tblCanceled;
// 高级检索条件
var searchCondition = {
    "storId":"",
    "shopId":"",
    "kind":"",
    "createTimeStart":"",
    "factInTimeStart":"",
    "finishTimeStart":"",
    "createTimeEnd":"",
    "factInTimeEnd":"",
    "finishTimeEnd":"",
    "goodsCode":"",
    "goodsName":"",
    "skuCode":"",
    "skuName":""
};

$(document).ready(function () {
    
    $('.panel-default .datetimepicker-default').datetimepicker();
    
    // 默认待发货显示
    getWaitReceive();
    getCounts();
    
    // 构建第三方仓库下拉列表
    $.ajax({
        type: "GET",
        url : "/stock/getStor.action",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                $("#storId option").remove();
                $("#storId").append("<option value=''>请选择</option>");
                $.each(data.data, function (n, value) {
                    $('#storId').append("<option value='" + value.storId + "'>" + value.storName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    // 构建店铺下拉列表
    $.ajax({
        type: "GET",
        url: "/shop/unpagedShopList.action?prjId=" + window.top.window.$("#projectSwitch").val(),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                $("#shopId option").remove();
                $("#shopId").append("<option value=''>请选择</option>");
                $.each(data.data, function (n, value) {
                    $('#shopId').append("<option value='" + value.shopId + "'>" + value.shopName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    $.validator.addMethod("checkLetter", function(value, element) {
        var reg = /^[0-9a-zA-Z\u4E00-\u9FA5\r\n\s/.]*$/; 
        if (!reg.test(value)) {
            return false;
        }
        
        return true;
    }, "请输入数字，大小写字母，汉字");

    $("#editForm").validate({
        debug:true,
        errorPlacement: function(error, element)
        {
            error.insertAfter(element);
        }
    });
    
});

// 设置高级查询条件
function setSearchCondition() {
    searchCondition = {
        "storId":encodeURI($('#storId').val()),
        "shopId":encodeURI($('#shopId').val()),
        "kind":encodeURI($('#kind').val()),
        "createTimeStart":encodeURI($('#createTimeStart').val()),
        "createTimeEnd":encodeURI($('#createTimeEnd').val()),
        "factInTimeStart":encodeURI($('#factInTimeStart').val()),
        "factInTimeEnd":encodeURI($('#factInTimeEnd').val()),
        "finishTimeStart":encodeURI($('#finishTimeStart').val()),
        "finishTimeEnd":encodeURI($('#finishTimeEnd').val()),
        "goodsCode":encodeURI($('#goodsCode').val()),
        "goodsName":encodeURI($('#goodsName').val()),
        "skuCode":encodeURI($('#skuCode').val()),
        "skuName":encodeURI($('#skuName').val())
    };
}

// 快速查询回车
$('#quickSearch').keydown(function(e){
    if (e.keyCode == 13 && $('#btnQuickSearch').is(":visible")) {
        $('#btnQuickSearch').click();
    }
});

// 快速查询按钮
$("#btnQuickSearch").click(function () {
    setSearchCondition();
    drawTable();
});

// 高级查询按钮
$("#advSearchSubmit").click(function () {
    setHidValue("frmAdvSearch");
    setSearchCondition();
    drawTable();
});

// 重置按钮
$("#advSearchReset").click(function() {
});

// 隐藏高级查询
$("#advSearchPanel").hide();
$("#btnAdvSearch").click(function () {
    if ($("#advSearchPanel").is(":hidden")) {
        $("#advSearchPanel").show();
        $("#btnQuickSearch").hide();
        $(this).children("i:eq(0)").removeClass("fa-angle-double-down");
        $(this).children("i:eq(0)").addClass("fa-angle-double-up");
    } else {
        $("#advSearchPanel").hide();
        $("#btnQuickSearch").show();
        $(this).children("i:eq(0)").removeClass("fa-angle-double-up");
        $(this).children("i:eq(0)").addClass("fa-angle-double-down");
    }
});

// 高级查询区域内单击
$("#advSearchPanel").click(function () {
})

// tab切换事件
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
    
    switch ($(this).attr("id")) {
        case "waitReceive":  //待收货
            getWaitReceive();
            break;
        // case "receiving":  //收货中
        //     getReceiving();
        //     break;
        case "complete":  //已完成
            getComplete();
            break;
        case "canceled":  //已取消
            getCanceled();
            break;
        default:
            break;
    }
    
    getCounts();
});

// tab显示时
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
    var tables = $.fn.dataTable.tables({
        visible : true,
        api : true
    });
    if (tables.length > 0) {
        $(tables).DataTable().columns.adjust();
    }
    $(tables).find("th.sorting_asc").removeClass("sorting_asc");
});

// 待收货列表
function getWaitReceive(){
    if (tblWaitReceive!=null && tblWaitReceive!=undefined && ""!=tblWaitReceive){
        tblWaitReceive.draw();
        return;
    }
    
    tblWaitReceive = $('#tblWaitReceive').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000] ],
        "dom": '<"bottom"rtflp>',
        "searching": false,
        "scrollX": true,
        "scrollCollapse": true,
        "pagingType": "full_numbers",
        "deferRender": true,
        "ajax": {
            "url": "/cainiaoReturnStockin/getReturnStockinList.action",
            "data": function (d) {
                d.returnStockinStatus = "waitReceive";
                d.quickSearch = encodeURI($('#quickSearch').val());
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools": {
            "sRowSelect": "bootstrap"
        },
        "columns": [
            {"data": "skuShow", "orderable": false},
            {"data": "stockinCode"},
            {"data": "wmsStockinCode"},
            {"data": "sourceCode",
                "render": function ( data, type, row, meta ) {
                    return '<a href="#" style="text-decoration:underline;" onclick="changeMenu(\'' + row.sourceCode + '\');">' + row.sourceCode + '</a>';
                },
            },
            {"data": "tradeCode"},
            {"data": "createTime"},
            {"data": "returnReasonName"},
            {"data": "shopName"},
            {"data": "buyerNick"},
            {"data": "cons"},
            {"data": "storName"},
            {"data": "remark"},
            {"data": "operation", "orderable": false}
        ],
        "columnDefs": [
            {"className": "truncate-text tooltip-column-detail", "targets":[1]},
            {"className": "truncate-text tooltip-column-detail", "targets":[2]},
            {"className": "truncate-text tooltip-column-detail", "targets":[3]},
            {"className": "truncate-text tooltip-column-detail", "targets":[4]},
            {"className": "truncate-text tooltip-column-detail", "targets":[5]},
            {"className": "truncate-text tooltip-column-detail", "targets":[6]},
            {"className": "truncate-text tooltip-column-detail", "targets":[7]},
            {"className": "truncate-text tooltip-column-detail", "targets":[8]},
            {"className": "truncate-text tooltip-column-detail", "targets":[9]},
            {"className": "truncate-text tooltip-column-detail", "targets":[10]}
        ],
        "order": [[5, "desc"]]
    });
    
    // 文字过长截断显示悬浮框
    $("#tblWaitReceive").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
}

// 收货中列表
function getReceiving(){
    if (tblReceiving!=null && tblReceiving != undefined && ""!=tblReceiving){
        tblReceiving.draw();
        showCancelRemark();
        return;
    }
    
    tblReceiving = $('#tblReceiving').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000] ],
        "dom": '<"bottom"rtflp>',
        "searching": false,
        "scrollX": true,
        "scrollCollapse": true,
        "pagingType": "full_numbers",
        "deferRender": true,
        "ajax": {
            "async": false,
            "url": "/returnStockin/getReturnStockinList.action",
            "data": function (d) {
                d.returnStockinStatus = "receiving";
                d.quickSearch = encodeURI($('#quickSearch').val());
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools": {
            "sRowSelect": "bootstrap"
        },
        "columns": [
            {"data": "skuShow", "orderable": false},
            {"data": "cancelStatus", 
                "render": function ( data, type, row, meta ) {
                    if (row.cancelStatus == "r") {
                        return "申请取消";
                    } else if (row.cancelStatus == "f") {
                        return "取消失败";
                    } else {
                        return "";
                    }
                }
            },
            {"data": "stockinCode"},
            {"data": "wmsStockinCode"},
            {"data": "sourceCode",
                "render": function ( data, type, row, meta ) {
                    return '<a href="#" style="text-decoration:underline;" onclick="changeMenu(\'' + row.sourceCode + '\');">' + row.sourceCode + '</a>';
                },
            },
            {"data": "tradeCode"},
            {"data": "createTime"},
            {"data": "returnReasonName"},
            {"data": "shopName"},
            {"data": "buyerNick"},
            {"data": "cons"},
            {"data": "storName"},
            {"data": "remark"},
            {"data": "operation", "orderable": false},
            {"data": "cancelRemark", "visible": false}
        ],
        "columnDefs": [
            {"className": "truncate-text tooltip-column-detail", "targets":[2]},
            {"className": "truncate-text tooltip-column-detail", "targets":[3]},
            {"className": "truncate-text tooltip-column-detail", "targets":[4]},
            {"className": "truncate-text tooltip-column-detail", "targets":[5]},
            {"className": "truncate-text tooltip-column-detail", "targets":[6]},
            {"className": "truncate-text tooltip-column-detail", "targets":[7]},
            {"className": "truncate-text tooltip-column-detail", "targets":[8]},
            {"className": "truncate-text tooltip-column-detail", "targets":[9]},
            {"className": "truncate-text tooltip-column-detail", "targets":[10]},
            {"className": "truncate-text tooltip-column-detail", "targets":[11]},
            {"className": "truncate-text tooltip-column-detail", "targets":[12]}
        ],
        "order": [[6, "desc"]]
    });
    
    showCancelRemark();
    
    // 文字过长截断显示悬浮框
    $("#tblReceiving").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
  
}

// 已完成列表
function getComplete(){
    if (tblComplete!=null && tblComplete != undefined && ""!=tblComplete){
        tblComplete.draw();
        showFinishRemark();
        return;
    }
    
    tblComplete = $('#tblComplete').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000] ],
        "dom": '<"bottom"rtflp>',
        "searching": false,
        "scrollX": true,
        "scrollCollapse": true,
        "pagingType": "full_numbers",
        "deferRender": true,
        "ajax": {
            "async": false,
            "url": "/cainiaoReturnStockin/getReturnStockinList.action",
            "data": function (d) {
                d.returnStockinStatus = "complete";
                d.quickSearch = encodeURI($('#quickSearch').val());
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools": {
            "sRowSelect": "bootstrap"
        },
        "columns": [
            {"data": "skuShow", "orderable": false},
            {"data": "finishType", 
                "render": function ( data, type, row, meta ) {
                    if (row.finishType == "z") {
                        return "正常完成";
                    } else {
                        return "<font color='red' style='font-weight:bolder;'>异常完成</font>";
                    }
                }
            },
            {"data": "stockinCode"},
            {"data": "wmsStockinCode"},
            {"data": "sourceCode",
                "render": function ( data, type, row, meta ) {
                    return '<a href="#" style="text-decoration:underline;" onclick="changeMenu(\'' + row.sourceCode + '\');">' + row.sourceCode + '</a>';
                },
            },
            {"data": "tradeCode"},
            {"data": "createTime"},
            {"data": "returnReasonName"},
            {"data": "shopName"},
            {"data": "buyerNick"},
            {"data": "cons"},
            {"data": "storName"},
            {"data": "remark"},
            {"data": "operation", "orderable": false},
            {"data": "finishRemark", "visible": false}
        ],
        "columnDefs": [
            {"className": "truncate-text tooltip-column-detail", "targets":[2]},
            {"className": "truncate-text tooltip-column-detail", "targets":[3]},
            {"className": "truncate-text tooltip-column-detail", "targets":[4]},
            {"className": "truncate-text tooltip-column-detail", "targets":[5]},
            {"className": "truncate-text tooltip-column-detail", "targets":[6]},
            {"className": "truncate-text tooltip-column-detail", "targets":[7]},
            {"className": "truncate-text tooltip-column-detail", "targets":[8]},
            {"className": "truncate-text tooltip-column-detail", "targets":[9]},
            {"className": "truncate-text tooltip-column-detail", "targets":[10]},
            {"className": "truncate-text tooltip-column-detail", "targets":[11]},
            {"className": "truncate-text tooltip-column-detail", "targets":[12]}
        ],
        "order": [[6, "desc"]]
    });
    
    showFinishRemark();
    
    // 文字过长截断显示悬浮框
    $("#tblComplete").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
}

// 已取消列表
function getCanceled(){
    if (tblCanceled!=null && tblCanceled != undefined && ""!=tblCanceled){
        tblCanceled.draw();
        return;
    }
    
    tblCanceled = $('#tblCanceled').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000] ],
        "dom": '<"bottom"rtflp>',
        "searching": false,
        "scrollX": true,
        "scrollCollapse": true,
        "pagingType": "full_numbers",
        "deferRender": true,
        "ajax": {
            "url": "/cainiaoReturnStockin/getReturnStockinList.action",
            "data": function (d) {
                d.returnStockinStatus = "canceled";
                d.quickSearch = encodeURI($('#quickSearch').val());
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools": {
            "sRowSelect": "bootstrap"
        },
        "columns": [
            {"data": "skuShow", "orderable": false},
            {"data": "cancelBeforeStatus"},
            {"data": "stockinCode"},
            {"data": "wmsStockinCode"},
            {"data": "sourceCode",
                "render": function ( data, type, row, meta ) {
                    return '<a href="#" style="text-decoration:underline;" onclick="changeMenu(\'' + row.sourceCode + '\');">' + row.sourceCode + '</a>';
                },
            },
            {"data": "tradeCode"},
            {"data": "createTime"},
            {"data": "returnReasonName"},
            {"data": "shopName"},
            {"data": "buyerNick"},
            {"data": "cons"},
            {"data": "storName"},
            {"data": "remark"}
        ],
        "columnDefs": [
            {"className": "truncate-text tooltip-column-detail", "targets":[1]},
            {"className": "truncate-text tooltip-column-detail", "targets":[2]},
            {"className": "truncate-text tooltip-column-detail", "targets":[3]},
            {"className": "truncate-text tooltip-column-detail", "targets":[4]},
            {"className": "truncate-text tooltip-column-detail", "targets":[5]},
            {"className": "truncate-text tooltip-column-detail", "targets":[6]},
            {"className": "truncate-text tooltip-column-detail", "targets":[7]},
            {"className": "truncate-text tooltip-column-detail", "targets":[8]},
            {"className": "truncate-text tooltip-column-detail", "targets":[9]},
            {"className": "truncate-text tooltip-column-detail", "targets":[10]},
            {"className": "truncate-text tooltip-column-detail", "targets":[11]},
            {"className": "truncate-text tooltip-column-detail", "targets":[12]}
        ],
        "order": [[6, "desc"]]
    });
    
    // 文字过长截断显示悬浮框
    $("#tblCanceled").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
}

// 取得tab上面的条数
function getCounts(){
    var data = {quickSearch:encodeURI($('#quickSearch').val()), formJson:JSON.stringify(searchCondition)};
    
    $.ajax({
        type: "GET",
        url: "/cainiaoReturnStockin/getReturnStockinListCount.action",
        data: data,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                $("#waitReceive").html("待收货(" + data.waitReceiveCount + ")");
                $("#receiving").html("收货中(" + data.receivingCount + ")");
                $("#complete").html("已完成(" + data.completeCount + ")");
                $("#canceled").html("已取消(" + data.canceledCount + ")");
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

// 子表格显示隐藏
$('.tablefirst tbody').on('click', 'td .sku-show', function () {
    var stockinId = $(this).attr('stockinId');
    var tr = $(this).closest('tr');
    var table;
    var row;
    var tablename =  "";
    $("div .active").each(function(){
        switch ($(this).attr("id")) {
        case "divWaitReceive":
            table = tblWaitReceive;
            row = tblWaitReceive.row(tr);
            tablename = "tblWaitReceive";
            break;
        // case "divReceiving":
        //     table = tblReceiving;
        //     row = tblReceiving.row(tr);
        //     tablename = "tblReceiving";
        //     break;
        case "divComplete":
            table = tblComplete;
            row = tblComplete.row(tr);
            tablename = "tblComplete"
            break;
        case "divCanceled":
            table = tblCanceled;
            row = tblCanceled.row(tr);
            tablename = "tblCanceled";
            break;
        default:
            break;
        }
    });
    // 加载过，而且是显示的状态
    if ( row.child.isShown() ) {
        row.child.hide();
        tr.removeClass('shown');
        $(this).removeClass('fa-chevron-up');
        $(this).addClass('fa-chevron-down');
    } else {
        // 关闭其他
        $('#'+tablename+' tbody tr').each(function(){
            if ($(this).attr("role")=="row"){
                table.row($(this)).child.hide();
            }
        });
        $('.fa-chevron-up').addClass('fa-chevron-down');
        $('.fa-chevron-down').removeClass('fa-chevron-up');
        
        var temp = '<iframe id="contentFrame" name="contentFrame" style="width:100%;" frameborder="0" scrolling="auto" src="/views/returnStockIn/sonReturnStockInList.html" width="100%" height="245"></iframe>';
        row.child(temp).show();
        tr.addClass('shown');
        $(this).addClass('fa-chevron-up');
        $(this).removeClass('fa-chevron-down');
        
        $('#stockinId').val(stockinId);
    }
});

// 重画表格
function drawTable() {
    $("div .active").each(function(){
        switch ($(this).attr("id")) {
            case "divWaitReceive":  //待收货
                tblWaitReceive.draw();
                break;
            // case "divReceiving":  //收货中
            //     tblReceiving.draw();
            //     showCancelRemark();
            //     break;
            case "divComplete":  //已完成
                tblComplete.draw();
                showFinishRemark();
                break;
            case "divCanceled":  //已取消
                tblCanceled.draw();
                break;
            default:
                break;
        }
    });
    
    getCounts();
}

// 改变菜单选中状态
function changeMenu(sourceCode) {
    window.top.window.$('a').each(function() {
        var str = $(this).attr("onclick");
        if (str!=undefined && str.indexOf("sysReturnList.html") > 0) {
            window.top.window.$("#returnCode").val(sourceCode);
            $(this).parents(':eq(2)').children('a').get(0).click();
            $(this).click();
            return false;
        }
    });
}

// 显示取消失败原因
function showCancelRemark() {
    $("#tblReceiving tbody tr").each(function() {
        var rowData = tblReceiving.row(this).data();
        if (rowData != undefined && rowData.cancelStatus == "f") {
            $(this).find("td").eq(1).attr("title", rowData.cancelRemark);
        }
    });
}

// 显示异常完成原因
function showFinishRemark() {
    $("#tblComplete tbody tr").each(function() {
        var rowData = tblComplete.row(this).data();
        if (rowData != undefined && rowData.finishType == "e") {
            $(this).find("td").eq(1).attr("title", rowData.finishRemark);
        }
    });
}

// 取消退货入库单
function operationCancel(btnCancel) {
    var stockinId = $(btnCancel).attr("stockinId");
    $.ajax({
        type: "POST",
        url: "/cainiaoReturnStockin/cancelReturnStockin/" + stockinId + ".action",
        data: null,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (json) {
            if (json.result=="success") {
                window.top.window.showModalAlert(json.data);
                drawTable();
            } else {
                window.top.window.showModalAlert(json.msg);
            }
        }
    });
}

// 弹出修改备注对话框
function operationUpdateRemark(btnEditRemark) {
    var stockinId = $(btnEditRemark).attr("stockinId");
    $.ajax({
        type: "POST",
        url: "/cainiaoReturnStockin/getReturnStockInInfo/" + stockinId + ".action",
        data: null,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                $('#stockinId_m').val(stockinId);
                $('#stockinCode_m').val(data.data.stockinCode);
                $('#remark_m').val(data.data.remark);
                var editDialog = window.top.window.borrowCustomModalDialog($("#frmModifyReturnStockIn"));
                editDialog.modal({show:true, backdrop:'static'});
            }
        }
    });

    $('#frmModifyReturnStockIn').modal('show');
}

// 关闭修改备注对话框
$('#frmModifyReturnStockIn').on('hidden.bs.modal', function () {
    $("#editForm")[0].reset();
});

// 关闭修改备注对话框
$('#frmModifyReturnStockIn').on('hide.bs.modal', function () {
    window.top.window.returnCustomModalDialog();
    $("#editForm").validate().clear();
})

// 保存修改备注
$("#btnSave_m").click(function () {
    window.top.window.returnCustomModalDialog();

    if(!$("#editForm").valid()) {
        window.top.window.borrowCustomModalDialog($("#frmModifyReturnStockIn"));
        return false;
    }

    var stockinId = $('#stockinId_m').val();
    var stockinCode = $('#stockinCode_m').val();
    var remark = $('#remark_m').val();
    var data = {
        "stockinId": stockinId,
        "stockinCode": stockinCode,
        "remark": remark
    }

    var edit=window.top.window.borrowCustomModalDialog($("#frmModifyReturnStockIn"));

    $.ajaxSettings['contentType'] = "application/x-www-form-urlencoded; charset=utf-8";

    $.ajax({
        type: "POST",
        url: "/cainiaoReturnStockin/updateReturnStockIn.action",
        data: JSON.stringify(data),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                edit.modal('hide');
                $('#remark_m').val('');
                window.top.window.showScoMessage('ok', '保存成功');
                drawTable();
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
});

// 导出
function exportReturnStockin() {
}

// 刷新
function refresh() {   
    refreshCheck();
    drawTable();
}
function refreshCheck(){
	$('#quickSearch').val("");
    $("#advSearchReset").click();
    searchCondition = {};
    if (!$("#advSearchPanel").is(":hidden")){
        $("#btnAdvSearch").click();   
    } 
}
